//CriticalSection.cpp
#include "CriticalSection.h"

CriticalSection::CriticalSection()
{
	InitializeCriticalSection(&m_stLock);
}

CriticalSection::~CriticalSection()
{
	DeleteCriticalSection(&m_stLock);
}

void CriticalSection::Lock()
{
	EnterCriticalSection(&m_stLock);
}

void CriticalSection::UnLock()
{
	LeaveCriticalSection(&m_stLock);
}

int CriticalSection::Lock(char &cZero)
{
	if (cZero) return COMMON_ERR_STATE;
	EnterCriticalSection(&m_stLock);
	cZero = 1;
	return 0;
}

int CriticalSection::UnLock(char &cZero)
{
	if (cZero == 0) return COMMON_ERR_STATE;
	LeaveCriticalSection(&m_stLock);
	cZero = 0;
	return 0;
}
